package tds.model22;
/**
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName Singleton2
 * @Description 单例模式之双重检测锁实现（缩小了同步的范围）.由于jvm底层内部模型和编译器优化
 * 原因，偶尔会出问题，不建议使用.https://blog.csdn.net/chenchaofuck1/article/details/51702129/
 * @author tds
 * @Date 2020/2/5 21:54
 * @version 1.0.0
 */
public class Singleton3 {
    private static Singleton3 instance;

    // 私有化构造方法，不允许自己实例化
    private Singleton3(){

    }

    public static  Singleton3 getInstance(){
        if(instance == null){
            Singleton3 sc = null;
            synchronized (Singleton3.class){
                sc = instance;
                synchronized (Singleton3.class){
                    if(sc == null){
                        instance = new Singleton3();
                    }
                }
            }
        }
        return instance;
    }

}
